const router = require('koa-router')();
const { v4: uuidv4} = require('uuid');
const bodyparser = require('koa-bodyparser');
const { redis } = require('../../config/env');
const RedisStore = require('koa-redis')(redis);

const Koa = require("koa");
const app = new Koa();

app.use(bodyparser());

router.all('/v1/user/logout', async (ctx, next) => {        //登出逻辑
    let session_id = ctx.cookies.get('session_id');
    ctx.session.logged = false;
    let sess = RedisStore.get(session_id);
    let result = await RedisStore.destroy(session_id);      //销毁内存中session,于登录时重新存入
    ctx.redirect('/v1/user/login');     //重定向至登录页面
    ctx.type = 'application/json';
    ctx.body = {
        code: 0,
        msg: '退出登录'
    }
});

module.exports = router.routes();